﻿#region 命名空间

using System;
using Microsoft.Practices.EnterpriseLibrary.PolicyInjection;
using WinnerCMS.BLL;
using WinnerCMS.Common;
using WinnerCMS.Model;
using WinnerCMS.Model.Attribute;

#endregion

namespace WinnerCMS.WebUI.Admin.CMSGG
{
    /// <summary>
    ///     广告管理
    /// </summary>
    [Access("260005")]
    public partial class List : WebFactory.PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindList(1);
            }
        }

        private void BindList(int pageNo)
        {
            var action = Request["Action"];

            if (action == null)
            {
                this.path.InnerHtml = "广告管理 → 正常广告";
            }
            else if (action == "MaxClick")
            {
                this.path.InnerHtml = "广告管理 → 点击最高";
            }
            else if (action == "MinClick")
            {
                this.path.InnerHtml = "广告管理 → 点击最低";
            }
            else if (action == "IsStop")
            {
                this.path.InnerHtml = "广告管理 → 暂停列表";
            }
            else if (action == "Invalidation")
            {
                this.path.InnerHtml = "广告管理 → 失效广告";
            }
            var pp = new PagingParam
            {
                PageSize = this.PageNavigation1.PageSize,
                PageNo = pageNo
            };

            this.DL_List.DataSource = new AdsManage().BindList(action, pp);
            this.DL_List.DataBind();

            this.PageNavigation1.RecordCount = pp.RecordCount;

            if (this.DL_List.Items.Count <= 0)
            {
                this.show1.Text = "<img src='/Images/NoData.gif'><br/>";
            }
            else
            {
                this.show1.Text = "";
            }
        }


        protected string TiaoJian(object maxClick, object maxShowTime, object maxDateTime)
        {
            var TJ = "";
            if (Convert.ToInt32(maxClick) > 0)
            {
                TJ = "点 击 数：" + maxClick + " ";
            }

            if (Convert.ToInt32(maxShowTime) > 0)
            {
                TJ += "显示数：" + maxShowTime + " ";
            }

            TJ += "显示期限：" + Convert.ToDateTime(maxDateTime).ToShortDateString();

            return TJ;
        }


        protected void PageNavigation1_PageChanging(object src, WebControls.PageChangingEventArgs e)
        {
            BindList(e.NewPageIndex);
        }

        protected void DL_List_ItemCommand(object source, System.Web.UI.WebControls.RepeaterCommandEventArgs e)
        {
            var id = e.CommandArgument.ToString();
            Result res = null;
            switch (e.CommandName)
            {
                case "stop":
                    res = PolicyInjection.Create<AdsManage>().StopOrOpen(id);
                    break;
                case "Del":
                    res = PolicyInjection.Create<AdsManage>().Delete(id);
                    break;
                case "Edit":
                    Response.Redirect("Add.aspx?ID=" + id);
                    break;
                case "JS":
                    new AdsManage().MakeJs(int.Parse(id));
                    MsgBox.Message("生成成功！", this.UpdatePanel1);
                    break;
            }
            if (res != null && res.Errors.Length > 0)
            {
                MsgBox.Message(res.Errors, this.UpdatePanel1);
            }
        }
    }
}